package com.course.design.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.course.design.dao.LtxxMapper;
import com.course.design.entity.Ltxx;
import com.course.design.entity.Ygxx;
import com.course.design.entity.vo.AllMessageVO;
import com.course.design.entity.vo.HistoryVO;
import com.course.design.entity.vo.MessageHisVO;
import com.course.design.entity.vo.MessageQueryVO;
import com.course.design.service.LtxxService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * 描述:
 *
 * @author qinlianji
 * @create 2020-02-19
 */
@Service
public class LtxxServiceImpl implements LtxxService {

    @Autowired
    private LtxxMapper ltxxMapper;

    @Override
    public void save(Ltxx ltxx) {
        ltxxMapper.insert(ltxx);
    }

    @Override
    public List<HistoryVO> getHistory(String userId) {
        return ltxxMapper.getHistory(userId);
    }

    @Override
    public IPage<Ygxx> queryUserHistory(int start, int limit, String ygghCd) {
        return ltxxMapper.queryUserHistory(new Page<>(start, limit) ,ygghCd);
    }

    @Override
    public List<MessageHisVO> queryMessageHistory(String fromUserId, String toUserId) {
        return ltxxMapper.queryMessageHistory(fromUserId, toUserId);
    }

    @Override
    public void clearUnread(MessageQueryVO vo) {
        ltxxMapper.clearUnread(vo);
    }

    @Override
    public List<AllMessageVO> queryAllMessage(List<MessageQueryVO> vo) {
        List<AllMessageVO> all = new ArrayList<>();
        AllMessageVO message = new AllMessageVO();
        List<MessageHisVO> hisvo = null;
        for (MessageQueryVO v : vo){
            hisvo = ltxxMapper.queryMessageHistory(v.getFromUserId(), v.getToUserId());
            all.add(message.setId(v.getToUserId()).setMessages(hisvo));
        }
        return all;
    }
}
